<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
import useOptions from '@/hooks/useOptions'
const props = defineProps<{
  show: boolean
  id: any[]
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  id: props.id.join(','),
  tagId: [],
})
const { options } = useOptions({ api: '/server-user/admin/user/tag/list', query: { status: 1 } })
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query: any = Object.assign({}, detail)
      query.tagId = detail.tagId.filter(Boolean).join(',')
      post(
        { url: '/server-user/admin/user/update/tag', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          if (code == 200) {
            emit('update:show', false)
            emit('confirm')
          }
          done(code == 200)
        },
        () => done(false)
      )
    } else done(false)
  })
}
</script>
<template>
  <CDrawer v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="500px" :title="props.id ? '编辑' : '新建'" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="标签" field="tagId" :rules="[{ required: true, message: '请输入标签' }]" :validate-trigger="['change', 'blur']">
          <a-select v-model="detail.tagId" multiple :options="options" placeholder="请输入标签" />
        </a-form-item>
      </a-form>
    </div>
  </CDrawer>
</template>
<style lang="less" scoped></style>
